<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>xadsr</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="wterrain.html" title="wterrain" />
    <link rel="next" href="xin.html" title="xin" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">xadsr</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="wterrain.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="xin.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="xadsr"></a>
      <div class="titlepage"></div>
      <a id="IndexXadsr" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">xadsr</span>
        </h2>
        <p>xadsr — 
      Calculates the classical ADSR envelope.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168721584"></a>
        <h2>Description</h2>
        <p>
      Calculates the classical ADSR envelope
   </p>
      </div>
      <div class="refsect1">
        <a id="idp168722768"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>xadsr</strong></span> iatt, idec, islev, irel [, idel]</pre>
        <pre class="synopsis">kres <span class="command"><strong>xadsr</strong></span> iatt, idec, islev, irel [, idel]</pre>
      </div>
      <div class="refsect1">
        <a id="idp168787216"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iatt</em></span> -- duration of attack phase
    </p>
        <p>
      <span class="emphasis"><em>idec</em></span> -- duration of decay
    </p>
        <p>
      <span class="emphasis"><em>islev</em></span> -- level for sustain phase
    </p>
        <p>
      <span class="emphasis"><em>irel</em></span> -- duration of release phase
    </p>
        <p>
      <span class="emphasis"><em>idel</em></span> -- period of zero before the envelope starts
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168792272"></a>
        <h2>Performance</h2>
        <p>
      The envelope generated is the range 0 to 1 and may need to be scaled 
      further, depending on the amplitude required. If using 
      <a class="link" href="Zerodbfs.html" title="0dbfs"><em class="citetitle">0dbfs</em></a> = 1, scaling down
      will probably be required since playing more than one note might result in clipping.
      If not using <a class="link" href="Zerodbfs.html" title="0dbfs"><em class="citetitle">0dbfs</em></a>, scaling
       to a large amplitude (e.g. 32000) might be required.
      </p>
        <p>
      The envelope may be described as:
      </p>
        <div class="mediaobject">
          <img src="images/adsr.png" alt="Picture of an ADSR envelope." />
          <div class="caption">
            <p>Picture of an ADSR envelope.</p>
          </div>
        </div>
        <p>
    </p>
        <p>
      The length of the sustain is calculated from the length of the note. This means <span class="emphasis"><em>xadsr</em></span> is not suitable for use with MIDI events, use <a class="link" href="mxadsr.html" title="mxadsr"><em class="citetitle">mxadsr</em></a> instead. The opcode <span class="emphasis"><em>xadsr</em></span> is identical to <a class="link" href="adsr.html" title="adsr"><em class="citetitle">adsr</em></a> except it uses exponential, rather than linear, line segments.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168802624"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the xadsr opcode. It uses the file <a class="ulink" href="examples/xadsr.csd" target="_top"><em class="citetitle">xadsr.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp168804480"></a>
          <p class="title">
            <strong>Example 1054. Example of the xadsr opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o xadsr.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="oblock">instr</span> 1

iatt  <span class="op">=</span> p5
idec  <span class="op">=</span> p6  
islev <span class="op">=</span> p7
irel  <span class="op">=</span> p8

kenv	<span class="opc">xadsr</span> iatt, idec, islev, irel
kcps <span class="op">=</span>  <span class="opc">cpspch</span>(p4) 	  <span class="comment">;frequency</span>

asig	<span class="opc">vco2</span>  kenv <span class="op">*</span> 0.8, kcps
	<span class="opc">outs</span>  asig, asig

<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span> 1  0  1  7.00  .0001  1  .01  .001 <span class="comment">; short attack</span>
<span class="stamnt">i</span> 1  2  1  7.02  1  .5  .01  .001    <span class="comment">; long attack</span>
<span class="stamnt">i</span> 1  4  2  6.09  .0001  1 .1  .7     <span class="comment">; long release</span>

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168808768"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="adsr.html" title="adsr"><em class="citetitle">adsr</em></a>,
      <a class="link" href="madsr.html" title="madsr"><em class="citetitle">madsr</em></a>,
      <a class="link" href="mxadsr.html" title="mxadsr"><em class="citetitle">mxadsr</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp168812736"></a>
        <h2>Credits</h2>
        <p>Author: John ffitch
      <span class="emphasis"><em>xadsr</em></span> is new in Csound version 3.51.
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="wterrain.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="xin.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">wterrain </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> xin</td>
        </tr>
      </table>
    </div>
  </body>
</html>
